package com.coscon.service.patternCommon.impl.mouse;

import com.coscon.model.IrcaCmd;
import com.coscon.service.patternCommon.ICommand;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import javax.websocket.Session;
import java.awt.*;
import java.awt.event.InputEvent;

/**
 * 鼠标按钮动作
 */
@Slf4j
public class MouseButtonCmdImpl implements ICommand {

    private Robot rb;

    public MouseButtonCmdImpl(Robot rb){
        this.rb = rb;
    }
    

    public Boolean execute(IrcaCmd cmd,  Session session) {
        if(StringUtils.equalsIgnoreCase(cmd.getValue(),"One" )){//单击
            log.debug("单击动作");
            rb.mousePress(InputEvent.BUTTON1_MASK);
            rb.mouseRelease(InputEvent.BUTTON1_MASK);
            rb.delay(50);
        }else if(StringUtils.equalsIgnoreCase(cmd.getValue(),"Double" )){//双击
            log.debug("双击动作");
            rb.mousePress(InputEvent.BUTTON1_MASK);
            rb.mouseRelease(InputEvent.BUTTON1_MASK);
            rb.delay(100);
            rb.mousePress(InputEvent.BUTTON1_MASK);
            rb.mouseRelease(InputEvent.BUTTON1_MASK);
            rb.delay(50);
        }else if(StringUtils.equalsIgnoreCase(cmd.getValue(),"Right" )){//右键
            log.debug("右键单击");
            //鼠标右键
            rb.mousePress(InputEvent.BUTTON3_MASK);
            rb.mouseRelease(InputEvent.BUTTON3_MASK);
        }
        return true;
    }

    @Override
    public Boolean executeByMac(IrcaCmd cmd, Session session) {
        return this.execute(cmd,session);
    }

    @Override
    public Boolean executeByWin(IrcaCmd cmd, Session session) {
        return this.execute(cmd,session);
    }

    @Override
    public Boolean executeByLinux(IrcaCmd cmd, Session session) {
        return this.execute(cmd,session);
    }


}
